package com.link2room.rodimus.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.rodimus.facade.IExpressFacadeService;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import com.link2room.rodimus.dto.param.api.ExpressListParamDto;
import com.link2room.rodimus.dto.param.api.ExpressUpdateParamDto;
import com.link2room.rodimus.dto.param.base.ExpressBaseDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.link2room.rodimus.constant.PermissionConstant.updateExpress;


/**
 * Created by LN on 2017/7/28.14:33
 */
@Api(tags = "发货相关")
@RestController
@RequestMapping("/manager/Expresses")
public class ExpressManagerController {

    @Resource
    private IExpressFacadeService expressFacadeService;

    @ApiOperation(value = "发货单列表", response = ExpressBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "sourceType",value = "发货单类型",paramType = "query",required = false),
            @ApiImplicitParam(name = "isDelivered",value = "是否发货",paramType = "query",required = false),
            @ApiImplicitParam(name = "mobile",value = "手机号",paramType = "query",required = false),
            @ApiImplicitParam(name = "thirdExpressNo",value = "第三方物流单号",paramType = "query",required = false),
            @ApiImplicitParam(name = "memberNo",value = "联房会员号",paramType = "query",required = false),
            @ApiImplicitParam(name = "receiverName",value = "收货人姓名",paramType = "query",required = false),
            @ApiImplicitParam(name = "sourceNo",value = "来源单号",paramType = "query",required = false),
            @ApiImplicitParam(name = "goodCode",value = "商品代码",paramType = "query",required = false),
            @ApiImplicitParam(name = "expressNo",value = "联房流水号",paramType = "query",required = false),

    })
    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto expresses(
            @RequestParam(name = "sourceType", required = false) String sourceType,
            @RequestParam(name = "isDelivered", required = false) String isDelivered,
            @RequestParam(name = "mobile", required = false) String mobile,
            @RequestParam(name = "thirdExpressNo", required = false) String thirdExpressNo,
            @RequestParam(name = "memberNo", required = false) String memberNo,
            @RequestParam(name = "receiverName", required = false) String receiverName,
            @RequestParam(name = "sourceNo", required = false) String sourceNo,
            @RequestParam(name = "goodCode", required = false) String goodCode,
            @RequestParam(name = "expressNo", required = false) String expressNo
    ) throws Exception {
        ExpressListParamDto paramDto = new ExpressListParamDto();
        paramDto.setSourceType(sourceType);
        paramDto.setSourceNo(sourceNo);
        paramDto.setIsDelivered(isDelivered);
        paramDto.setMobile(mobile);
        paramDto.setMemberNo(memberNo);
        paramDto.setThirdExpressNo(thirdExpressNo);
        paramDto.setMemberNo(memberNo);
        paramDto.setReceiverName(receiverName);
        paramDto.setGoodCode(goodCode);
        paramDto.setExpressNo(expressNo);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setQueryResult(expressFacadeService.expressList(paramDto));
        return resDto;
    }


    @ApiOperation(value = "发货单修改")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "expressNo",value = "联房流水号",paramType = "query",required = false),
    })
    @RequestMapping(value = "/{expressNo}",method = RequestMethod.POST)
    @L2RPermissionResources(value = updateExpress,name="更新发货详情")
    public BaseResultDto expresses(
            @RequestBody ExpressUpdateParamDto paramDto,
            @PathVariable("expressNo") String expressNo) throws Exception {
        paramDto.setExpressNo(expressNo);
        expressFacadeService.updateExpress(paramDto);
        paramDto.setExpressNo(expressNo);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }

}
